﻿using System;
using System.Data;
using System.Text;
using System.Data.OleDb;

namespace storeSMS.DAL
{
	/// <summary>
	/// 数据访问类:storeinfo
	/// </summary>
	public partial class storeinfo
	{
		public storeinfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
            return DbHelperOleDb.GetMaxID("ID", "storeinfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from storeinfo");
			strSql.Append(" where ID=@ID");
			OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)
			};
			parameters[0].Value = ID;

			return DbHelperOleDb.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Maticsoft.Model.storeinfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into storeinfo(");
			strSql.Append("gys,project,projectbh,cgddh,phone,qr,gh,nums)");
			strSql.Append(" values (");
			strSql.Append("@gys,@project,@projectbh,@cgddh,@phone,@qr,@gh,@nums)");
			OleDbParameter[] parameters = {
					new OleDbParameter("@gys", OleDbType.VarChar,255),
					new OleDbParameter("@project", OleDbType.VarChar,255),
					new OleDbParameter("@projectbh", OleDbType.VarChar,255),
					new OleDbParameter("@cgddh", OleDbType.VarChar,255),
					new OleDbParameter("@phone", OleDbType.VarChar,255),
					new OleDbParameter("@qr", OleDbType.Date),
					new OleDbParameter("@gh", OleDbType.Date),
					new OleDbParameter("@nums", OleDbType.VarChar,255)};
			parameters[0].Value = model.gys;
			parameters[1].Value = model.project;
			parameters[2].Value = model.projectbh;
			parameters[3].Value = model.cgddh;
			parameters[4].Value = model.phone;
			parameters[5].Value = model.qr;
			parameters[6].Value = model.gh;
			parameters[7].Value = model.nums;

			int rows=DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Maticsoft.Model.storeinfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update storeinfo set ");
			strSql.Append("gys=@gys,");
			strSql.Append("project=@project,");
			strSql.Append("projectbh=@projectbh,");
			strSql.Append("cgddh=@cgddh,");
			strSql.Append("phone=@phone,");
			strSql.Append("qr=@qr,");
			strSql.Append("gh=@gh,");
			strSql.Append("nums=@nums");
			strSql.Append(" where ID=@ID");
			OleDbParameter[] parameters = {
					new OleDbParameter("@gys", OleDbType.VarChar,255),
					new OleDbParameter("@project", OleDbType.VarChar,255),
					new OleDbParameter("@projectbh", OleDbType.VarChar,255),
					new OleDbParameter("@cgddh", OleDbType.VarChar,255),
					new OleDbParameter("@phone", OleDbType.VarChar,255),
					new OleDbParameter("@qr", OleDbType.Date),
					new OleDbParameter("@gh", OleDbType.Date),
					new OleDbParameter("@nums", OleDbType.VarChar,255),
					new OleDbParameter("@ID", OleDbType.Integer,4)};
			parameters[0].Value = model.gys;
			parameters[1].Value = model.project;
			parameters[2].Value = model.projectbh;
			parameters[3].Value = model.cgddh;
			parameters[4].Value = model.phone;
			parameters[5].Value = model.qr;
			parameters[6].Value = model.gh;
			parameters[7].Value = model.nums;
			parameters[8].Value = model.ID;

			int rows=DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from storeinfo ");
			strSql.Append(" where ID=@ID");
			OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)
			};
			parameters[0].Value = ID;

			int rows=DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from storeinfo ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperOleDb.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.storeinfo GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,gys,project,projectbh,cgddh,phone,qr,gh,nums from storeinfo ");
			strSql.Append(" where ID=@ID");
			OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)
			};
			parameters[0].Value = ID;

			Maticsoft.Model.storeinfo model=new Maticsoft.Model.storeinfo();
			DataSet ds=DbHelperOleDb.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.storeinfo DataRowToModel(DataRow row)
		{
			Maticsoft.Model.storeinfo model=new Maticsoft.Model.storeinfo();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=int.Parse(row["ID"].ToString());
				}
				if(row["gys"]!=null)
				{
					model.gys=row["gys"].ToString();
				}
				if(row["project"]!=null)
				{
					model.project=row["project"].ToString();
				}
				if(row["projectbh"]!=null)
				{
					model.projectbh=row["projectbh"].ToString();
				}
				if(row["cgddh"]!=null)
				{
					model.cgddh=row["cgddh"].ToString();
				}
				if(row["phone"]!=null)
				{
					model.phone=row["phone"].ToString();
				}
				if(row["qr"]!=null && row["qr"].ToString()!="")
				{
					model.qr=DateTime.Parse(row["qr"].ToString());
				}
				if(row["gh"]!=null && row["gh"].ToString()!="")
				{
					model.gh=DateTime.Parse(row["gh"].ToString());
				}
				if(row["nums"]!=null)
				{
					model.nums=row["nums"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,gys,project,projectbh,cgddh,phone,qr,gh,nums ");
			strSql.Append(" FROM storeinfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOleDb.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM storeinfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            object obj = DbHelperOleDb.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from storeinfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOleDb.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OleDbParameter[] parameters = {
					new OleDbParameter("@tblName", OleDbType.VarChar, 255),
					new OleDbParameter("@fldName", OleDbType.VarChar, 255),
					new OleDbParameter("@PageSize", OleDbType.Integer),
					new OleDbParameter("@PageIndex", OleDbType.Integer),
					new OleDbParameter("@IsReCount", OleDbType.Boolean),
					new OleDbParameter("@OrderType", OleDbType.Boolean),
					new OleDbParameter("@strWhere", OleDbType.VarChar,1000),
					};
			parameters[0].Value = "storeinfo";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOleDb.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

